package com.xidian.zhiancloud.controller.systemset;

import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.service.user.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统设置 地理位置信息设计
 *
 * @Author: Summerless
 * @Date: 2021/2/4 13:34
 */
@RestController
@RequestMapping("/position")
public class PositionController extends BaseController{

    @Autowired
    PositionService positionService;

    /**
     * 地理位置列表
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/getPositionList")
    public ResultDTO getPositionList(){
        Long companyid=this.getSessionUserCompanyId();
        return ResultDTO.successOf(positionService.getPositionList(companyid),
                GeneralResponseEnums.SUCCESS);
    }

    /**
     * 增加地理位置信息节点
     * @param pid 父节点ID
     * @param name 节点名称
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/addPositionList")
    public ResultDTO addPositionList (
        @RequestParam(value="pid",required = false,defaultValue = "0") Integer pid,
        @RequestParam(value="name") String name) {
        Long companyid=this.getSessionUserCompanyId();
        positionService.addPositionList(pid,name,companyid);
        return ResultDTO.successOf(positionService.getPositionList(companyid),
                GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除地理位置信息节点
     * @param id 地理位置信息ID
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping(value = "/deletePositionList")
    public ResultDTO deletePositionList(@RequestParam("id") String id){
        Long companyid=this.getSessionUserCompanyId();
        positionService.deletePositionList(id);
        return ResultDTO.successOf
                (positionService.getPositionList(companyid),
                        GeneralResponseEnums.SUCCESS);
    }



}
